﻿namespace FitnessTracker.DataStructures
{
    using System.Collections.Concurrent;

    public class FixedSizeQueue<T> : ConcurrentQueue<T>
    {
        public FixedSizeQueue(int size)
        {
            Size = size;
        }

        private int Size { get; set; }

        public new void Enqueue(T obj)
        {
            base.Enqueue(obj);
            lock (this)
            {
                while (this.Count > Size)
                {
                    T outObj;
                    this.TryDequeue(out outObj);
                }
            }
        }
    }
}
